/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * @tc.name:asyncUseLazyImport
 * @tc.desc:test asyncUseLazyImport
 * @tc.type: FUNC
 * @tc.require: issue#IB2HNC
 */

// @ts-nocheck
import lazy { TestLazy } from './lazyExport';
export class Test {
    async start() {
        try {
            this.log(` Test start`)
            let a = await this.mapAsync([1, 2], async (t) => {
                await this.bindRawData(t)
            })
            this.log(` Test end ${new Error().stack}`)
            throw new Error();
        } catch (e) {
            this.log(` Test catch`)
        } finally {
            this.log(` Test finally`)
        }
    }
    private async bindRawData(t: number) {
        await this.mapAsync([1, 2], async (k, b) => {
            this.onBindRawData(t, k)
        })
        await this.mapAsync([4, 5], async (k, b) => {
            this.onBindRawData(t, k)
        })
        await this.mapAsync([7, 8], async (k, b) => {
            this.onBindRawData(t, k)
        })
    }
    async mapAsync<T, U>(array: T[], map: (t: T, index: number) => Promise<U>) {
        return await Promise.all(array.map(map))
    }
    private async onBindRawData(t: number, k: number) {
        this.log(` onBindRawData start ${t} ${k}`)
        await this.isSelf()
        this.log(` onBindRawData end ${t} ${k}`)
    }
    private async isSelf(): Promise<boolean> {
        return "1" == "1"
    }
    log(msg: string) {
        TestLazy
        print(msg)
    }
}